package com.zrwl.poscloud.xo.service.impl;

import com.zrwl.poscloud.base.entity.UserServiceOrderUse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import com.zrwl.poscloud.xo.mapper.UserBlackMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import com.zrwl.poscloud.xo.mapper.UserServiceOrderUseMapper;
import com.zrwl.poscloud.xo.service.UserServiceOrderUseService;
import com.zrwl.poscloud.xo.vo.UserServiceOrderUseVO;

import javax.annotation.Resource;

/**
 * 服务使用记录 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-01
 */
@Service
public class UserServiceOrderUseServiceImpl extends SuperServiceImpl<UserServiceOrderUseMapper, UserServiceOrderUse> implements UserServiceOrderUseService {

    @Autowired
    private UserServiceOrderUseService userServiceOrderUseService;
    @Resource
    private UserServiceOrderUseMapper userServiceOrderUseMapper;

    @Override
    public IPage<UserServiceOrderUseVO> getPageList(UserServiceOrderUseVO userServiceOrderUseVO) {
        Page<UserServiceOrderUse> page = new Page<>();
        page.setCurrent(userServiceOrderUseVO.getCurrentPage());
        page.setSize(userServiceOrderUseVO.getPageSize());
        IPage<UserServiceOrderUseVO> pageList = userServiceOrderUseMapper.getPageList(page, userServiceOrderUseVO);
        List<UserServiceOrderUseVO> list = pageList.getRecords();
        pageList.setRecords(list);
        return pageList;
    }

    @Override
    public List<UserServiceOrderUse> getAllList(UserServiceOrderUseVO userServiceOrderUseVO) {
        QueryWrapper<UserServiceOrderUse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_uid", userServiceOrderUseVO.getOrderUid());
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<UserServiceOrderUse> list = userServiceOrderUseService.list(queryWrapper);
        return list;
    }

    @Override
    public String add(UserServiceOrderUseVO userServiceOrderUseVO) {
        UserServiceOrderUse entity = new UserServiceOrderUse();
        BeanUtils.copyProperties(userServiceOrderUseVO, entity, SysConf.STATUS);
        entity.insert();
        userServiceOrderUseVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);
    }

    @Override
    public String edit(UserServiceOrderUseVO userServiceOrderUseVO) {
        UserServiceOrderUse entity = userServiceOrderUseService.getById(userServiceOrderUseVO.getUid());
        BeanUtils.copyProperties(userServiceOrderUseVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }

    @Override
    public String delete(UserServiceOrderUseVO userServiceOrderUseVO) {
        UserServiceOrderUse entity = userServiceOrderUseService.getById(userServiceOrderUseVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
    }
}
